package com.smartum.mpr.business;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartum.mpr.dao.UserDao;
import com.smartum.mpr.dao.UserSearchDao;
import com.smartum.mpr.dto.Filter;
import com.smartum.mpr.exception.DatabaseIntegrityException;
import com.smartum.mpr.exception.NotExistsTokenException;
import com.smartum.mpr.exception.NotExistsUserException;
import com.smartum.mpr.model.User;
import com.smartum.mpr.model.UsersFriends;
import com.smartum.mpr.model.UsersFriendsRequest;

@Service
public class UserSearchBusiness extends BaseBusiness {

	@Autowired
	private UserSearchDao userSearchDao;
	@Autowired
	private UserDao userDao;
	
	
	public User getById(long id){
		return userDao.get(id);
	}
	
	
	public void connected(String token, User userToConnect) throws DatabaseIntegrityException,
    NotExistsUserException, NotExistsTokenException {
		
		UsersFriendsRequest solicitud=new UsersFriendsRequest();
		solicitud.setUsersByUserId(userDao.findUserByToken(token));//FROM 
		solicitud.setUsersByUserIdFriend(userToConnect); //TO
		solicitud.setStatus('0');
		solicitud.setDate(new Date());
		userSearchDao.saveRequest(solicitud);
		
    }
	
	public List<User> findListUserFriendsRequest(String token) throws DatabaseIntegrityException,
    NotExistsUserException, NotExistsTokenException {
    return userSearchDao.findListUserFriendsRequest(userDao.findUserByToken(token));
    }


	public List<UsersFriends> findListUserFriendsByUser(String token) throws DatabaseIntegrityException,
	         NotExistsUserException, NotExistsTokenException {
		 return userSearchDao.findListUserFriendsByUser(userDao.findUserByToken(token));
	}
	
	public List<UsersFriends> findListUserFriendsYouMayknowByUser(String token) throws DatabaseIntegrityException,
    NotExistsUserException, NotExistsTokenException {
     return userSearchDao.findListUserFriendsYouMayknowByUser(this.findListUserFriendsByUser(token));
    }
	
	public List<User> findListUserFriendsFilterByUser(String token,Filter filter) throws DatabaseIntegrityException,
    NotExistsUserException, NotExistsTokenException {
     return userSearchDao.findListUserFriendsFilterByUser(userDao.findUserByToken(token),filter);
    }
	
	public List<User> findListUserFriendsSearch(String token) throws DatabaseIntegrityException,
    NotExistsUserException, NotExistsTokenException {
     return userSearchDao.findListUserFriendsSearch(userDao.findUserByToken(token));
    }
	
	

}
